package net.aiion.weave.spi.resources;

import java.util.ServiceLoader;

public abstract class ResourceFinderFactory
{
    private static ResourceFinderFactory instance;

    public ResourceFinderFactory() {
    }

    public abstract ResourceFinder createResourceFinder();

    public static ResourceFinderFactory getInstance() {
        if (instance == null) {
            for (ResourceFinderFactory resourceFinderFactory : ResourceFinderFactoryServiceLoader.SERVICE_LOADER) {
                instance = resourceFinderFactory;
                break;
            }
        }

        return instance;
    }

    private static final class ResourceFinderFactoryServiceLoader
    {
        private static final ServiceLoader<ResourceFinderFactory> SERVICE_LOADER = ServiceLoader
            .load(ResourceFinderFactory.class);

        private ResourceFinderFactoryServiceLoader() {
        }
    }
}
